package com.shangan.shortlink.admin.util;

import java.util.Random;

/**
 * 随机字符串生成器
 * @author Jerryzaj
 * @Date 2024/6/17 19:45
 */
public final class RandomStringGenerator {
  
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";  
    private static final int STRING_LENGTH = 6;  
    private static final Random RANDOM = new Random();  
  
    // 私有构造函数，防止实例化  
    private RandomStringGenerator() {  
        throw new AssertionError("No instances for you!");  
    }  
  
    // 生成随机字符串的方法  
    public static String generateRandomString() {  
        StringBuilder sb = new StringBuilder(STRING_LENGTH);  
        for (int i = 0; i < STRING_LENGTH; i++) {  
            int index = (int) (RANDOM.nextFloat() * CHARACTERS.length());  
            sb.append(CHARACTERS.charAt(index));  
        }  
        return sb.toString();  
    }  
  
    // 主方法，用于测试  
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {  
            System.out.println(generateRandomString());  
        }  
    }  
}